/*
简单工厂模式
*/

package simple_factory

// 对外的接口
type SayService interface {
	Say() string
}

// 工厂方法 NewXxx
func NewSayService(typ string) SayService {
	if typ == "hi" {
		return &hiService{}
	}
	if typ == "hello" {
		return &helloService{}
	}
	return nil
}

// 具体实现细节不对外暴露
type hiService struct {
}
type helloService struct {
}

func (h *hiService) Say() string {
	return "hi"
}

func (h *helloService) Say() string {
	return "hello"
}
